package com.rayc.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;
@Component
public class RedisLockUtil {
    @Autowired
    private RedisTemplate redisTemplate;
    //加锁
    public boolean lock(String key, String value,int second){
        return redisTemplate.opsForValue().setIfAbsent(key, value, second, TimeUnit.SECONDS);
    }
    //释放锁
    public void unlock(String key){
        redisTemplate.delete(key);
    }
}
